home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Periodicals / CSMP / C.S.M.P. Digest, Issue 3.028 < prev    next >
Internet Message Format  |  1994-06-09  |  62KB

  1. From: pottier@clipper.ens.fr (Francois Pottier)
  2. Subject: csmp-digest-v3-028
  3. Date: Wed, 18 May 94 14:13:10 MET DST
  4.  
  5. C.S.M.P. Digest             Wed, 18 May 94       Volume 3 : Issue 28
  6.  
  7. Today's Topics:
  8.  
  9.         CRC-16 routine in C for native code
  10.         CodeWarrior Gold Education Price
  11.         How to write a bullet-proof lib?
  12.         PixMap to mask
  13.         Posting an event to another application?
  14.         Shared memory...
  15.         Unmounting all volumes?
  16.  
  17.  
  18.  
  19. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  20. (pottier@clipper.ens.fr).
  21.  
  22. The digest is a collection of article threads from the internet newsgroup
  23. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  24. regularly and want an archive of the discussions.  If you don't know what a
  25. newsgroup is, you probably don't have access to it.  Ask your systems
  26. administrator(s) for details.  If you don't have access to news, you may
  27. still be able to post messages to the group by using a mail server like
  28. anon.penet.fi (mail help@anon.penet.fi for more information).
  29.  
  30. Each issue of the digest contains one or more sets of articles (called
  31. threads), with each set corresponding to a 'discussion' of a particular
  32. subject.  The articles are not edited; all articles included in this digest
  33. are in their original posted form (as received by our news server at
  34. nef.ens.fr).  Article threads are not added to the digest until the last
  35. article added to the thread is at least two weeks old (this is to ensure that
  36. the thread is dead before adding it to the digest).  Article threads that
  37. consist of only one message are generally not included in the digest.
  38.  
  39. The digest is officially distributed by two means, by email and ftp.
  40.  
  41. If you want to receive the digest by mail, send email to listserv@ens.fr
  42. with no subject and one of the following commands as body:
  43.     help                        Sends you a summary of commands
  44.     subscribe csmp-digest Your Name    Adds you to the mailing list
  45.     signoff csmp-digest            Removes you from the list
  46. Once you have subscribed, you will automatically receive each new
  47. issue as it is created.
  48.  
  49. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  50. Questions related to the ftp site should be directed to
  51. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  52. digest are available there.
  53.  
  54. Also, the digests are available to WAIS users as comp.sys.mac.programmer.src.
  55.  
  56.  
  57. -------------------------------------------------------
  58.  
  59. >From satcomm@aol.com (SatComm)
  60. Subject: CRC-16 routine in C for native code
  61. Date: 30 Apr 1994 14:40:08 -0400
  62. Organization: America Online, Inc. (1-800-827-6364)
  63.  
  64. I'm looking to replace some old code in assembly that calculated the standard
  65. Xmodem/MacBinary CRC-16 stuff.  Unfortunately, I think I threw away all
  66. remnants of my CRC stuff when I discovered the assembly routine.  Does anyone
  67. have a CRC routine for this in C?
  68.  
  69. Thanks.
  70.  
  71. satcomm@aol.com
  72.  
  73. +++++++++++++++++++++++++++
  74.  
  75. >From david@oahu.cs.ucla.edu (David Dantowitz)
  76. Date: Sun, 01 May 94 16:36:57 GMT
  77. Organization: UCLA, Computer Science Department
  78.  
  79. Here's some code and information on CRCs I put together some years
  80. back.  It is in the public domain.
  81.  
  82. David
  83.  
  84. - --------- cut here --------------
  85. /*
  86.  
  87.    Computing CRCs
  88.  
  89.    This set of implementations was written by David M. Dantowitz, and
  90.    has been placed in the public domain, to be used at the user's
  91.    discretion.  The original code was implemented in Turbo Pascal 3.0
  92.    this submission is a version written in C.
  93.  
  94.    This program demonstrates various ways by which Cyclic
  95.    Redundancy Checks (CRC) may be computed and their relative speeds.
  96.  
  97.  
  98.    CRC polynomials in this program are represented by replacing
  99.    each term that is non-zero with a 1 and each zero term with a 0.
  100.    Note that the highest order bits represent the low order terms 
  101.    of the polynomial.
  102.  
  103.    Thus X^3+X^1+1 becomes 1101 and X^4+X^1+1 becomes 11001.
  104.  
  105.    Now, since all polynomials have a highest term (X^a) we drop the
  106.    highest term during computation (shift right one bit, dropping
  107.    the low bit).
  108.  
  109.  
  110.    Here are some examples of conversion from symbolic to binary
  111.    representation (but not necessarily polynomials with desirable
  112.    CRC properties):
  113.  
  114.  
  115.            Polynomial                Representation     Hex
  116.  
  117.           X^5 + X^2 + 1                  10100          $14
  118.  
  119.             X^7 + 1                     1000000         $40
  120.  
  121.           X^3+X^2+X^1+1                   111           $7
  122.  
  123.           X^6+X^5+X^3+1                 100101          $25
  124.  
  125.  
  126.    For a good discussion of polynomial selection see "Cyclic
  127.    Codes for Error Detection", by W. W. Peterson and
  128.    D. T. Brown, Proceedings of the IEEE, volume 49, pp 228-235,
  129.    January 1961.
  130.  
  131.    A reference on table driven CRC computation is "A Cyclic
  132.    Redundancy Checking (CRC) Algorithm" by A. B. Marton and
  133.    T. K. Frambs, The Honeywell Computer Journal, volume 5,
  134.    number 3, 1971.
  135.  
  136.    Also used to prepare these examples was "Computer Networks",
  137.    by Andrew S. Tanenbaum, Prentice Hall, Inc.  Englewood Cliffs,
  138.    New Jersey, 1981.
  139.  
  140.    The following four polynomials are international standards:
  141.  
  142.  
  143.         CRC-12 = X^12 + X^11 + X^3 + X^2 + X^1 + 1
  144.         CRC-16 = X^16 + X^15 + X^2 + 1
  145.         CRC-CCITT = X^16 + X^12 + X^5 + 1
  146.         CCITT-32 = X^32 + X^26 + X^23 + X^22 + X^16 + X^12 + X^11 + X^10 +
  147.                    X^8 + X^7 + X^5 + X^4 + X^2 + X^1 + 1
  148.  
  149.    In Binary and hexadecimal :
  150.  
  151.                    Binary                     Hex
  152.  
  153.         CRC-12    = 1111 0000 0001           $0F01
  154.         CRC-16    = 1010 0000 0000 0001      $A001
  155.         CRC-CCITT = 1000 0100 0000 1000      $8404    (Used below)
  156.         CCITT-32  = 1110 1101 1011 1000 
  157.                     1000 0011 0010 0000      $EDB88320
  158.  
  159.    The first is used with 6-bit characters and the second two
  160.    with 8-bit characters.  All of the above will detect any
  161.    odd number of errors.  The second two will catch all 16-bit
  162.    bursts, a high percentage of 17-bit bursts (~99.997%) and
  163.    also a large percentage of 18-bit or larger bursts (~99.998%).
  164.    The paper mentioned above (Peterson and Brown) discusses how 
  165.    to compute the statistics presented which have been quoted 
  166.    from Tanenbaum.
  167.  
  168.    (A burst of length N is defined a sequence of N bits, where
  169.    the first and last bits are incorrect and the bits in the
  170.    middle are any possible combination of correct and incorrect.
  171.    See the paper by Peterson and Brown for more information)
  172.  
  173.    Note that when using a polynomial of degree N, the CRC is the
  174.    first N bits of the value returned by the routines below.
  175.    (e.g. with CRC-12, the CRC is bits 0 to 11 of the CRC value,
  176.    with the other two mentioned above, the CRC is all 16 bits.)
  177.  
  178.  
  179.    Here is a quick idea of what is being calculated ...
  180.  
  181.    The CRC is the residual from division of the data stream by
  182.    the CRC polynomial.  The data stream is also thought of as a
  183.    polynomial, with the highest order term being the lowest bit
  184.    of the first byte of the data stream and the lowest order term
  185.    of the polynomial being the high bit of the last byte of data.
  186.    The actual division is performed on the data stream polynomial
  187.    multiplied by X^y where y is the degree of the CRC polynomial.
  188.  
  189.  
  190.    All math used to compute CRCs is done modulo 2.  This means the
  191.    following relationships are used:
  192.  
  193.  
  194.                 0+0=0    0+1=1    1+0=1    1+1=0   (XOR)
  195.                 0-0=0    0-1=1    1-0=1    1-1=0   (XOR)
  196.                 0*0=0    0*1=0    1*0=0    1*1=1   (AND)
  197.  
  198.    Thus addition and subtraction have NO carries or borrows.
  199.  
  200.                                              
  201.    Here is a sample computation showing the actual division.
  202.  
  203.  
  204.    Polynomial = X^4+X^3+1; Data = $94.
  205.  
  206.    The division performed is 1001 into 0010 1001.  Notice that
  207.    the highest order terms of the data polynomial are the lowest
  208.    order bits of the data stream.  We will also multiply the
  209.    dividend by X^4 as noted above:
  210.  
  211.              1011011  - The quotient is not important and is discarded.
  212.    1001/001010010000
  213.          -1001  ----    The extra 0s result from multiplying the data by X^4
  214.           ----
  215.             1101 <--    The code below calculates this value
  216.            -1001
  217.             ----
  218.              1000
  219.             -1001
  220.              ----
  221.                 1000
  222.                -1001
  223.                 ----
  224.                 0001  This is the CRC (the residual from the division)!
  225.  
  226.  
  227.    The code below does not shift the data by the number of bits
  228.    equal to the degree of the CRC polynomial.  There is no ill effect
  229.    caused by not doing this multiply.  Now, the result of the CRC computation
  230.    is just the residue from the division of the data by the CRC.  
  231.  
  232.  
  233.    None of the routines below appear to compute a division.  In the example
  234.    above the subtractions are really XORs (pronounced exclusive OR).  XOR
  235.    has the same behavior as +/- in modulo two arithmetic, so it is used
  236.    in the computations.  The first CRC routine below (Simple_CRC) models
  237.    the computation lucidly.  The other routines use various optimization
  238.    techniques to speed the computation.
  239.  
  240.  
  241.    CRC use ...
  242.  
  243.    The CRC is appended to the end of the original data stream (or stored
  244.    separetely).  When the receiver gets the data stream, the CRC is again
  245.    computed and matched against the received CRC, if the two do not match
  246.    then an error has most likely occurred.  
  247.  
  248.  
  249.    My address is
  250.  
  251.    David Dantowitz
  252.    Dantowitz Consulting and Research
  253.    P.O. Box 8105
  254.    Englewood, NJ  07631
  255.  
  256.    (201) Low-Bug-C
  257.    AppleLink: Dantowitz
  258. */
  259.  
  260. #include <stdio.h>
  261. #include <string.h>
  262.  
  263.  
  264. #define INITIAL_CRC 0xFFFFFFFF
  265.  
  266.  
  267. /*
  268.    This result was obtained by calling make_crc_table(0xedb88320).
  269. */
  270.  
  271.  
  272. int             crc_table[16] =
  273. {
  274.   0x00000000,
  275.   0xfdb71064,
  276.   0xfb6e20c8,
  277.   0x06d930ac,
  278.   0xf6dc4190,
  279.   0x0b6b51f4,
  280.   0x0db26158,
  281.   0xf005713c,
  282.   0xedb88320,
  283.   0x100f9344,
  284.   0x16d6a3e8,
  285.   0xeb61b38c,
  286.   0x1b64c2b0,
  287.   0xe6d3d2d4,
  288.   0xe00ae278,
  289.   0x1dbdf21c
  290. };
  291.  
  292.  
  293.  
  294. make_crc_table(crc_poly)
  295.   int             crc_poly;
  296. {
  297.   int             i, val, result;
  298.  
  299.   for (val = 0; val < 16; val++)
  300.   {
  301.     result = val;
  302.  
  303.     for (i = 0; i < 4; i++)
  304.       if (result & 1)
  305.     result = (result >> 1) ^ crc_poly;
  306.       else
  307.     result >>= 1;
  308.  
  309.     crc_table[val] = result;
  310.  
  311.     printf("0x%08lx\n", result);
  312.   }
  313.  
  314. }
  315.  
  316. int
  317. compute_crc(old_crc, s, len)
  318.   int             old_crc;
  319.   char           *s;
  320.   int             len;
  321. {
  322.   int             i;
  323.  
  324.   for (i = 0; i < len; i++)
  325.  
  326.   {
  327. /*
  328.    XOR in the data.
  329. */
  330.  
  331.     old_crc ^= s[i];
  332. /*
  333.    Perform the XORing for each nybble
  334. */
  335.     old_crc = (old_crc >> 4) ^ crc_table[old_crc & 0x0f];
  336.     old_crc = (old_crc >> 4) ^ crc_table[old_crc & 0x0f];
  337.   }
  338.  
  339.   return (old_crc);
  340. }
  341.  
  342. main()
  343. {
  344.   char            line[100];
  345.   int             crc_val;
  346.   int             len;
  347.  
  348. /*   make_crc_table(0xedb88320); done at compile time... */
  349.  
  350. /*
  351.    initialize the crc -- start with this value each time you start
  352.    a session.
  353. */
  354.   crc_val = INITIAL_CRC;
  355.  
  356.   strcpy(line, "This will test the crc function");
  357.  
  358.   len = strlen(line);
  359.  
  360.  
  361.   crc_val = compute_crc(crc_val, line, len);
  362.  
  363. /* 
  364.    let's add MORE text to the CRC -- they can be cumulative across many
  365.    blocks of data.
  366. */
  367.  
  368.   strcpy(line, "More text to add");
  369.  
  370.   len = strlen(line);
  371.  
  372.   crc_val = compute_crc(crc_val, line, len);
  373.  
  374. }
  375.  
  376. -- 
  377. David Dantowitz
  378. david@cs.ucla.edu
  379.  
  380. Singing Barbershop when I'm not doing parallel simulation
  381.  
  382. +++++++++++++++++++++++++++
  383.  
  384. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  385. Date: Mon, 2 May 1994 18:51:22 +1200 (NZST)
  386. Organization: (none)
  387.  
  388. satcomm@aol.com (SatComm) writes:
  389. > I'm looking to replace some old code in assembly that calculated the standard
  390. > Xmodem/MacBinary CRC-16 stuff.  Unfortunately, I think I threw away all
  391. > remnants of my CRC stuff when I discovered the assembly routine.  Does anyone
  392. > have a CRC routine for this in C?
  393.  
  394. Here's a routine for checking the Macbinary header CRC.  I'm not sure what
  395. XModem uses:
  396.  
  397. - --------------
  398. #define CCITT_CRC_GEN    0x1021
  399.  
  400. short CalcCRC(register unsigned char *dataBuf, register long size)
  401. {
  402.     register unsigned short    crc = 0;
  403.     register unsigned short    dataByte;
  404.     register long i;
  405.     
  406.     while (size--)
  407.     {
  408.         dataByte = *dataBuf++ << 8;
  409.         for (i = 8; i > 0; i--)
  410.         {
  411.             if ((dataByte ^ crc) & 0x8000)
  412.                 crc = (crc << 1) ^ CCITT_CRC_GEN;
  413.             else
  414.                 crc <<= 1 ;
  415.             dataByte <<= 1;
  416.         }
  417.     }
  418.     return(crc);
  419. }
  420. - --------------
  421.  
  422.  
  423. For my own use, I've recoded it slightly in a way that gives much better code
  424. on unsophisticated compilers such as MPW C.  I was able to alternate operations
  425. on different data, which should probably help a little on pipelined CPUs (I
  426. don't know how much), and spelling things out a little more explicitely stopped
  427. a lot of data moves etc that weren't needed.
  428.  
  429. Treating C as a two-address assembly language seems to help many compilers a
  430. lot...  :-)
  431.  
  432. - --------------
  433. #define CCITT_CRC_GEN    0x1021
  434.  
  435. short CalcCRC(register unsigned char *dataBuf, register long size)
  436. {
  437.     register unsigned long crc = 0;
  438.     register unsigned long dataByte;
  439.     register long i;
  440.     
  441.     while (--size >= 0)
  442.     {
  443.         dataByte = *dataBuf++;
  444.         dataByte <<= 8;
  445.         i = 8;
  446.         do {    
  447.             register long bit = dataByte;
  448.             dataByte += dataByte;
  449.             bit ^= crc;
  450.             crc += crc;
  451.             if (bit &= 0x8000)
  452.                 crc ^= CCITT_CRC_GEN;
  453.         } while (--i);
  454.     }
  455.     return crc;
  456. }
  457. - --------------
  458.  
  459. +++++++++++++++++++++++++++
  460.  
  461. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  462. Date: Mon, 2 May 1994 19:15:41 +1200 (NZST)
  463. Organization: (none)
  464.  
  465. satcomm@aol.com (SatComm) writes:
  466. > I'm looking to replace some old code in assembly that calculated the standard
  467. > Xmodem/MacBinary CRC-16 stuff.  Unfortunately, I think I threw away all
  468. > remnants of my CRC stuff when I discovered the assembly routine.  Does anyone
  469. > have a CRC routine for this in C?
  470.  
  471. Further to my last post, and to (hopefully) forstall email, yes I am aware
  472. that a bit-by-bit algorithm for CRC isn't the fastest way to do it, no
  473. matter how efficiently coded.
  474.  
  475. It was good enough for my purpose (which was checking a smallish Macbinary
  476. header), and I was more interested in code size than in speed (for reasons
  477. I won't go into...).
  478.  
  479. -- Bruce
  480.  
  481. ---------------------------
  482.  
  483. >From cvafy002@csupomona.edu
  484. Subject: CodeWarrior Gold Education Price
  485. Date: 25 Apr 94 14:32:09 PST
  486. Organization: California State Polytechnic University, Pomona
  487.  
  488. I have a friend who'd like to get CodeWarrior Gold at the education price (I
  489. read it was $99). How would he go about getting it? He doesn't have internet
  490. access. How can he find out if his College and/or he qualifies?
  491.  
  492.  
  493. +++++++++++++++++++++++++++
  494.  
  495. >From mwron@aol.com (MW Ron)
  496. Date: 27 Apr 1994 21:16:03 -0400
  497. Organization: America Online, Inc. (1-800-827-6364)
  498.  
  499. In article <1994Apr25.143209.1@clstac>, cvafy002@csupomona.edu writes:
  500. >>I have a friend who'd like to get CodeWarrior Gold at the education price (I
  501. read it was $99). How would he go about getting it? He doesn't have internet
  502. access. How can he find out if his College and/or he qualifies?
  503.  
  504. I think this will be helpful to all of you strugling students.
  505.  
  506. For educational prices, BookMasters is our distributor and their phone number
  507. is 1-800-247-6553 in the US. Educational pricing is as such:
  508.  
  509.                 Gold    $99.00 US
  510.                 Silver  $79.00 US
  511.                 Bronze  $59.00 US
  512.  
  513. $15.00 shipping and handling US orders.
  514.  
  515. You must fax BookMasters proof that you are either a student or officially
  516. affilliated with a University.  Their fax number is(419) 281-6883.
  517.  
  518. Ron Liechty
  519. mwron@aol.com
  520. Metrowerks Inc.
  521.  
  522. +++++++++++++++++++++++++++
  523.  
  524. >From cs2ev@herts.ac.uk (Mas)
  525. Date: 28 Apr 1994 17:29:59 +0100
  526. Organization: University of Hertfordshire
  527.  
  528.   Dear all
  529.  
  530.     Please do tell me the difference between gold, silver & bronze
  531. versions of codewarrior.  Thanks
  532.  
  533. Andre-John MAS
  534.  
  535.  
  536. +++++++++++++++++++++++++++
  537.  
  538. >From mwron@aol.com (MW Ron)
  539. Date: 28 Apr 1994 20:46:02 -0400
  540. Organization: America Online, Inc. (1-800-827-6364)
  541.  
  542. In article <2pooa7$dej@altair.herts.ac.uk>, cs2ev@herts.ac.uk (Mas) writes:
  543.  
  544. Please do tell me the difference between gold, silver & bronze versions of
  545. codewarrior.  
  546.  
  547. >>GOLD    Includes all for 68K Macintosh and Power Macintosh as well
  548. as 68K-hosted PowerPC compilers.  
  549.  
  550. SILVER   Includes all for PowerPC Only (no 68K Macintosh  compilers or
  551. linkers)
  552.  
  553. BRONZE  Includes all for 68K Macintosh (no PowerPC compilers or
  554. linkers) 
  555.  
  556. Ron Liechty
  557. mwron@aol.com
  558. Metrowerks Inc.
  559.  
  560. +++++++++++++++++++++++++++
  561.  
  562. >From zee@fwi.uva.nl (Daniel vd Zee)
  563. Date: 3 May 1994 14:15:03 GMT
  564. Organization: FWI, University of Amsterdam
  565.  
  566. mwron@aol.com (MW Ron) writes:
  567. >For educational prices, BookMasters is our distributor and their phone number
  568. >is 1-800-247-6553 in the US. Educational pricing is as such:
  569. >                Gold    $99.00 US
  570. >                Silver  $79.00 US
  571. >                Bronze  $59.00 US
  572. >$15.00 shipping and handling US orders.
  573. How about non-US students, are the pricing and the distributor the same and
  574. do i have to get some kind of internalional student card to order?
  575.  
  576. Thanx,
  577. Daniel (zee@fwi.uva.nl)
  578.  
  579.  
  580.  
  581. +++++++++++++++++++++++++++
  582.  
  583. >From mwron@aol.com (MW Ron)
  584. Date: 4 May 1994 17:10:03 -0400
  585. Organization: America Online, Inc. (1-800-827-6364)
  586.  
  587. In article <2q5m97$4dv@hermes.fwi.uva.nl>, zee@fwi.uva.nl (Daniel vd Zee)
  588. writes:
  589. >> How about non-US students, are the pricing and the distributor the same and
  590. do i have to get some kind of internalional student card to order?
  591.  
  592. I do not know if we have  or do not have any  international educational
  593. discounts you would have to contact one of the following to find out what the
  594. item is in your particular country.
  595.  
  596. Japan       -  B.U.G. in Sapporo,  Applelink = BUGPLAN.DVJ
  597.  
  598. Australia   -  Techflow in Australia, Applelink = TECHFLOW
  599.  
  600. Germay      -  pandasoft in Berlin, Germany, telephone= (49) 3031 5913 16
  601.  
  602. All others,   BookMasters
  603.  
  604.                        U.S./Canada:   1-800-247-6553
  605.                        International:   1-419-281-1802
  606.                        Fax No.:   1-419-281-6883
  607. Everywhere else in the world, including Europe out of Germany should be taken
  608. direct through our distributor BookMasters.
  609.  
  610. Ron Liechty
  611. mwron@aol.com
  612. Metrowerks Inc.
  613.  
  614. +++++++++++++++++++++++++++
  615.  
  616. >From neeri@iis.ee.ethz.ch (Matthias Neeracher)
  617. Date: 4 May 1994 22:34:08 GMT
  618. Organization: Swiss Federal Institute of Technology (ETHZ)
  619.  
  620. mwron@aol.com (MW Ron) writes:
  621. >In article <2q5m97$4dv@hermes.fwi.uva.nl>, zee@fwi.uva.nl (Daniel vd Zee)
  622. >writes:
  623. >>> How about non-US students, are the pricing and the distributor the same and
  624. >do i have to get some kind of internalional student card to order?
  625.  
  626. >I do not know if we have  or do not have any  international educational
  627. >discounts 
  628.  
  629. Yes you do. It was no problem getting the Ed. Discount from Switzerland.
  630.  
  631. >All others,   BookMasters
  632.  
  633. >                       Fax No.:   1-419-281-6883
  634.  
  635. I got my copy of CodeWarrior from BookMasters. All I had to do was to fax
  636. them a copy of my Student ID and my credit card number. They messed up
  637. the reply to my first fax, but once I had sent the order, I got CW within
  638. 4 or 5 working days... well done, BookMasters!
  639.  
  640. Matthias
  641.  
  642. - ---
  643. Matthias Neeracher                                      neeri@iis.ee.ethz.ch
  644.   "Do not mess with any jumper you do not know about even if it is labeled
  645.    SEX and FREE BEER" -- Dave Haynie
  646.  
  647. ---------------------------
  648.  
  649. >From mpcline@cats.ucsc.edu (Matthew Paul Cline)
  650. Subject: How to write a bullet-proof lib?
  651. Date: 1 May 1994 23:35:06 GMT
  652. Organization: University of California, Santa Cruz
  653.  
  654.  
  655.     I am writing a library for the Mac, and would like it to be
  656. bullet-proof.  When I say bullet proof, I'm using the term in a paranoid
  657. way: if a customer calls up and complains that he/she can't use it to
  658. make a desktop accessory, I can't say "Well, Apple recommends against
  659. making a desktop accessory"; thus, I am not using any global variables
  660. in the library (the only thing I know programming a desktop accessory).
  661. Given my level of paranoia, is it possible to make a bullet-proof
  662. library?  Or can I just get cloose to bullet-proof?  Any help would be
  663. appreciated.
  664.  
  665. P.S.: Am I being paranoid, or is this the way you should go about
  666. making a library?
  667. -- 
  668. X-phile, GATB               Have you hugged your shoggoth today?
  669. GE d? p c++(+++) l++ u++ e+ m+ s/- n+(-) h+ f !g w+ t+ r y+
  670.  
  671. +++++++++++++++++++++++++++
  672.  
  673. >From Matt Slot <fprefect@engin.umich.edu>
  674. Date: 2 May 1994 07:15:30 GMT
  675. Organization: University of Michigan
  676.  
  677. Matthew Paul Cline, mpcline@cats.ucsc.edu writes:
  678.  
  679. >P.S.: Am I being paranoid, or is this the way you should go about
  680. >making a library?
  681.  
  682. I dont think its paranoid to put something out that you feel is stable
  683. enough for others to want to use. If I get a library that I think
  684. isn't of good quality or has some bugs in it, I dont feel comfortable
  685. putting it into my own software.
  686.  
  687. When I wrote my Gamma Libs, I tried to test it on as many computers
  688. as I could and make it work for the widest audience possible. These
  689. are the things I learned:
  690.  
  691.     * Use simple interfaces and explain them well enough that others
  692.       can use them easily. Calling a function with wrong information
  693.       is an easy way to make anything barf.
  694.       
  695.     * Comment the rest of your code (if provided) so users can see
  696.       what you are trying to do and can make improvments/changes as
  697.       fits their needs. (And bug feedback is much easier too)
  698.       
  699.     * Use the best programming styles and follow the books, technotes
  700.       and advice you can find to make the software as compatible for
  701.       future versions.
  702.       
  703.     * Use Gestalt and other calls make sure you are able to run in
  704.       a given environment and that your memory calls succeed. 
  705.       Returning error codes is very important.
  706.       
  707.     * Try it out in a test app (making a demo program with source is
  708.       really nice), and run it with various system configurations
  709.       and extensions. Clearly define a minimum system that you require,
  710.       such as Mac Plus, System 6 or 7, or Color QD.
  711.       
  712.     * Run it with heap scrambling and Even Better Bus Error. A user
  713.       trying to use software with my library complained that EBBE
  714.       flagged it... and it helped me to clean up some skanky pointer
  715.       arithmetic.
  716.       
  717.     * Look for testers who will give you feedback before you make
  718.       the libs public... so you dont get your lib branded before it
  719.       gets popular. 
  720.       
  721.     * Beg for programmer and user feedback, and try to work with others
  722.       who come to you with odd problems.
  723.       
  724. Hope this helps... good luck with your library. 
  725.  
  726. Matt
  727.  
  728. +++++++++++++++++++++++++++
  729.  
  730. >From gurgle@netcom.com (Pete Gontier)
  731. Date: Mon, 2 May 1994 07:01:34 GMT
  732. Organization: cellular
  733.  
  734. mpcline@cats.ucsc.edu (Matthew Paul Cline) writes:
  735.  
  736. >I am writing a library for the Mac, and would like it to be
  737. >bullet-proof. ...thus, I am not using any global variables in the
  738. >library (the only thing I know programming a desktop accessory).
  739.  
  740. It depends on what your library does, of course; I hope you're allowed
  741. to post that so we can consider it. But, in general, you'll have to be
  742. careful about some other things as well as global variables. If your
  743. library is bigger than 32K, that's as bad as having globals, because any
  744. number of segments greater than one causes many of the same problems as
  745. global variables. Also be careful about calls which assume a valid A5
  746. world. Many QuickDraw calls, for example, assume they own the A5 world.
  747.  
  748. One alternative which takes care of many problems is to provide two
  749. copies of the library, one for A5-based projects (apps) and the other
  750. for A4-based projects (everything else). Of course, under MPW, there is
  751. no such thing as a code resource which has global variables, so even a
  752. separate A4-based lib will not help you there, so it is better to avoid
  753. globals altogether.
  754.  
  755. >P.S.: Am I being paranoid, or is this the way you should go about
  756. >making a library?
  757.  
  758. Be paranoid. Be very very paranoid. :-)
  759.  
  760. As long as you understand low-level Mac programming, and as long as your
  761. boss is happy with the notion of a reasonable beta period, you should be
  762. OK. Your testers may not find bugs in your code, but they can probably
  763. be counted on to have problems linking your library into their projects,
  764. even if you do everything right! :-) Resolving any linking problems they
  765. have which are actually your fault won't be half as nasty as any one bug
  766. hunt.
  767. -- 
  768.  Pete Gontier, CTO, Integer Poet Software; gurgle@netcom.com
  769.  
  770.  "Reality is 50 million polygons per second." -- Alvy Ray Smith
  771.  
  772. +++++++++++++++++++++++++++
  773.  
  774. >From d88-jwa@dront.nada.kth.se (Jon W‰tte)
  775. Date: 2 May 1994 08:50:58 GMT
  776. Organization: The Royal Institute of Technology
  777.  
  778. In <2q29ai$hcl@lastactionhero.rs.itd.umich.edu> Matt Slot <fprefect@engin.umich.edu> writes:
  779.  
  780. >    * Use simple interfaces and explain them well enough that others
  781. >      can use them easily. Calling a function with wrong information
  782. >      is an easy way to make anything barf.
  783.  
  784. Have a debugging version of your library, which calls
  785. Debugger() when it detects inconsistent data, parameters
  786. out of range or unexpected return values BEFORE returning
  787. them. A simple ASSERT() macro will do this!
  788.  
  789. >    * Use Gestalt and other calls make sure you are able to run in
  790. >      a given environment and that your memory calls succeed. 
  791. >      Returning error codes is very important.
  792.  
  793. Actually, the library probably shouldn't call Gestalt. Maybe a
  794. separate little utility rouinte, in source, which just made
  795. sure that everything's OK and returned a Boolean. Let the user's
  796. code do the checking, for instance by calling your separate
  797. utility routine.
  798.  
  799. >    * Beg for programmer and user feedback, and try to work with others
  800. >      who come to you with odd problems.
  801.  
  802. Especially: be responsive, and take every complaint seriously.
  803. -- 
  804.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe (on a Swedish scale) --
  805.  
  806.    There's no problem that can't be solved using brute-force algorithms
  807.    and a sufficiently fast computer. Ergo, buy more hardware.    (NOT!)
  808.  
  809. +++++++++++++++++++++++++++
  810.  
  811. >From mpcline@cats.ucsc.edu (Matthew Paul Cline)
  812. Date: 2 May 1994 17:56:24 GMT
  813. Organization: University of California, Santa Cruz
  814.  
  815.  
  816. In <gurgleCp5y6M.4KL@netcom.com> gurgle@netcom.com (Pete Gontier) writes:
  817.  
  818. >mpcline@cats.ucsc.edu (Matthew Paul Cline) writes:
  819.  
  820. >>I am writing a library for the Mac, and would like it to be
  821. >>bullet-proof. ...thus, I am not using any global variables in the
  822. >>library (the only thing I know programming a desktop accessory).
  823.  
  824. >It depends on what your library does, of course; I hope you're allowed
  825. >to post that so we can consider it.
  826.  
  827. It uses the Novell socket library on top of MacTCP.
  828.  
  829. >                                     But, in general, you'll have to be
  830. >careful about some other things as well as global variables.
  831.  
  832. Since this is a port of an already existing library, I'm replacing all
  833. global variables with static variables local to one file, and then
  834. using get_GLOBAL() and set_GLOBAL() type function calls.  Does that
  835. still have the problem of globals variables?  What about staic variables
  836. within a procedure?
  837.  
  838. >                                                              If your
  839. >library is bigger than 32K, that's as bad as having globals, because any
  840. >number of segments greater than one causes many of the same problems as
  841. >global variables.
  842.  
  843. I was planning on either using pluged-in code resources or using ASLM.
  844. Would this also be bad for a library?
  845.  
  846. [snip]
  847.  
  848. >As long as you understand low-level Mac programming.
  849.  
  850. Hmmm, might have a problem here: I'm very new to the Mac.  My boss
  851. basically hired me and said: "Here, go and learn everything you need to
  852. know about the Mac and port our library to it."  Do you have any advice
  853. on taking a crash course on low-level Mac programming?  Thanks in
  854. advance.
  855. -- 
  856. X-phile, GATB               Have you hugged your shoggoth today?
  857. GE d? p c++(+++) l++ u++ e+ m+ s/- n+(-) h+ f !g w+ t+ r y+
  858.  
  859. +++++++++++++++++++++++++++
  860.  
  861. >From rmah@panix.com (Robert S. Mah)
  862. Date: Mon, 02 May 1994 19:25:06 -0500
  863. Organization: One Step Beyond
  864.  
  865. mpcline@cats.ucsc.edu (Matthew Paul Cline) wrote:
  866.  
  867. > Since this is a port of an already existing library, I'm replacing all
  868. > global variables with static variables local to one file, and then
  869. > using get_GLOBAL() and set_GLOBAL() type function calls.  Does that
  870. > still have the problem of globals variables?  What about staic variables
  871. > within a procedure?
  872.  
  873. Using statics will prevent name space pollution but the variables 
  874. themselves are still referenced like globals.  That is they are accessed 
  875. via offsets from register a5.  This will fall down if the code is being 
  876. used in drivers, extensions or anything without a proper a5 world.
  877.  
  878. One option is to build two sets of libraries, one compiled using a5 
  879. offsets and another using a4 offsets.  This is the technique used by
  880. Symantec for their ANSI libraries, for example.
  881.  
  882. Cheers,
  883. Rob
  884. ___________________________________________________________________________
  885. Robert S. Mah  -=-  One Step Beyond  -=-  212-947-6507  -=-  rmah@panix.com
  886.  
  887. +++++++++++++++++++++++++++
  888.  
  889. >From gurgle@netcom.com (Pete Gontier)
  890. Date: Tue, 3 May 1994 18:40:42 GMT
  891. Organization: cellular
  892.  
  893. mpcline@cats.ucsc.edu (Matthew Paul Cline) writes:
  894.  
  895. >It uses the Novell socket library on top of MacTCP.
  896.  
  897. OK, if you are porting, then you do need to be careful the code you are
  898. porting doesn't use any global variables or use the 'static' modifier
  899. for variables declared inside functions. It's possible to let the code
  900. do these things, depending on the compiler in use, but you do need to be
  901. aware of it so you can make sure it works -- or document how to make it
  902. work, if it needs to be the caller's responsibility.
  903.  
  904. >Since this is a port of an already existing library, I'm replacing all
  905. >global variables with static variables local to one file, and then
  906. >using get_GLOBAL() and set_GLOBAL() type function calls. Does that
  907. >still have the problem of globals variables?
  908.  
  909. Yes. What your routines are doing is hiding the globals, to a certain
  910. extent, and that's marginally good in terms of maintainability. But
  911. the machine doesn't care how maintainable your code is. :-) The hidden
  912. globals are still globals in terms of where they are stored in memory
  913. at run-time, that is at offsets from register A5 (apps) or register A4
  914. (everything else).
  915.  
  916. >What about staic variables within a procedure?
  917.  
  918. Same problem, as I said above.
  919.  
  920. >>If your library is bigger than 32K, that's as bad as having globals,
  921. >>because any number of segments greater than one causes many of the
  922. >>same problems as global variables.
  923.  
  924. >I was planning on either using pluged-in code resources or using ASLM.
  925. >Would this also be bad for a library?
  926.  
  927. I don't know much about ASLM except that it's not available in a fairly
  928. large subset of installed Systems. And last I heard, it required MPW
  929. C++, but that restriction has probably gone away by now.
  930.  
  931. But, if you are stuffing this code into a code resource, I can tell you
  932. you won't have to concern yourself with two different versions of a
  933. linkable library file any more. Your project will be A4-based, and you
  934. can look up and understand the use of <SetUpA4.h> and be done with it.
  935. You can also have code larger than 32K without much difficulty.
  936.  
  937. There are a couple of drawbacks to a code resource, though.
  938.  
  939. First, there's the fact that if you want more than one entry point,
  940. you must create them yourself. In other words, the calling program
  941. should probably call the code resource's main entry point with the
  942. understanding that all that will result is a list of other entry points
  943. into the code resource. I'm basically talking about a structure full of
  944. function pointers here.
  945.  
  946. You will also have to write *another* library to be linked into programs
  947. in order to avoid the chore of documenting for others how to call your
  948. external code resource. (Believe me, writing this extra library is much
  949. better than writing a document about code resources, because people will
  950. call you for tech support no matter how good your doc is.) Fortunately,
  951. this extra library will probably be simple enough that you can include
  952. source code instead of a library file without revealing any trade
  953. secrets.
  954.  
  955. TAKE-HOME MESSAGE:
  956.  
  957. I think your best bet is to do linkable libraries. They involve the
  958. fewest technical headaches. You'll actually have to do three of them
  959. (one for A5, one for A4, and one for PowerPC), but once you have done
  960. one, the rest will follow pretty easily. You'll also have a 32K limit on
  961. each library file, but you can always do more than one library file for
  962. each kind of project.
  963.  
  964. >>As long as you understand low-level Mac programming...
  965.  
  966. >Hmmm, might have a problem here: I'm very new to the Mac. My boss
  967. >basically hired me and said: "Here, go and learn everything you need to
  968. >know about the Mac and port our library to it."
  969.  
  970. Tell your boss right away that aspects of this project are beyond your
  971. field of expertise. The Macintosh issues are fairly simple for a very
  972. experienced Mac programmer, but for someone new to the Mac, they can
  973. be really ugly and take a lot more time than you would like. It will
  974. be especially frustrating if you know all there is to know about the
  975. networking aspects of the job and are constrained only by the Mac
  976. aspects, because your boss may not understand that. If you tell her now,
  977. you'll be able to plan ahead.
  978.  
  979. >Do you have any advice on taking a crash course on low-level Mac
  980. >programming?
  981.  
  982. Of course, if there is no way to tell your boss, then you have just
  983. embarked on the best low-level Mac programming course there is!
  984. Experience: 12 units. Unfortunately, it's also the *only* course. Good
  985. luck, and the net will be here when you need it. :-)
  986. -- 
  987.  Pete Gontier, CTO, Integer Poet Software; gurgle@netcom.com
  988.  
  989.  You thought Obfuscated C was confusing? Wait for Obfuscated C++!
  990.  
  991. ---------------------------
  992.  
  993. >From adamnash@Xenon.Stanford.EDU (Adam Nash)
  994. Subject: PixMap to mask
  995. Date: 2 May 1994 06:28:05 GMT
  996. Organization: Computer Science Department, Stanford University.
  997.  
  998.  
  999. This may be really simple, but I wanted to check with the net first
  1000. in case this has been done a better way.  I'm converting a PixMap
  1001. (from a Pict) into a Mask for that item.  Now, if you call BitMapToRegion
  1002. you get a nasty speckle because, it translates anything more than "half
  1003. white" to white, when I want every non-white pixel to be black.
  1004. So, I was going to roll my own PixMapToMask, which went through the
  1005. pixel data and every time it hit a value > 0, it would put a black pixel in
  1006. a temporary BitMap, then call BitMapToRgn.
  1007.  
  1008. What do you think, all you sprite and offscreen gurus out there?
  1009.  
  1010. -Adam
  1011.  
  1012. +++++++++++++++++++++++++++
  1013.  
  1014. >From daniel@unx.al.alcoa.com (David L. Daniel)
  1015. Date: 2 May 1994 13:51:41 GMT
  1016. Organization: Alcoa
  1017.  
  1018. In article <2q26hl$f72@Times.Stanford.EDU>, adamnash@Xenon.Stanford.EDU
  1019. (Adam Nash) wrote:
  1020. > So, I was going to roll my own PixMapToMask, which went through the
  1021. > pixel data and every time it hit a value > 0, it would put a black pixel in
  1022. > a temporary BitMap, then call BitMapToRgn.
  1023.  
  1024. You could try using SeedCFill and CalcCMask, but I have had lots of trouble
  1025. using these - not just understanding them (which can be difficult), but
  1026. also with inconsistent results.  Others have expressed similar problems.
  1027. Here is some code that I use to do what you want.  No guarantees, but it
  1028. seems to work for me.  The argument "ignoreColor" is the pixel value
  1029. that you want to be ignored in creating a mask.  Good luck.
  1030.  
  1031.  
  1032. /* ######################################################################
  1033. */
  1034. /* Make a mask for a PixMap (put it into a BitMap). */
  1035.  
  1036. void MakeMask(unsigned char ignoreColor, PixMapHandle pmHndl, BitMapHandle
  1037. bmHndl)
  1038. {
  1039.     short            i,j,k,bmBytes,pmBytes,bmBit,cols,rows;
  1040.     unsigned char    *bmPtr,*pmPtr;
  1041.     
  1042.  
  1043.     cols = (**pmHndl).bounds.right - (**pmHndl).bounds.left;
  1044.     rows = (**pmHndl).bounds.bottom - (**pmHndl).bounds.top;
  1045.  
  1046.     /*if the image rectangles are not the same dimensions, then return an
  1047. error*/
  1048.     if( ( cols != ((**bmHndl).bounds.right - (**bmHndl).bounds.left))
  1049.         || ( rows != ((**bmHndl).bounds.bottom - (**bmHndl).bounds.top)) )
  1050.         return;
  1051.     
  1052.     /*Get the number of rowBytes for each image*/
  1053.     pmBytes = (0x1fff & (**pmHndl).rowBytes);
  1054.     bmBytes = (**bmHndl).rowBytes;
  1055.  
  1056.     /*Determine the starting address for the rectangles in each image*/
  1057.     pmPtr=(unsigned char*) ((**pmHndl).baseAddr +
  1058. pmBytes*(**pmHndl).bounds.top + (**pmHndl).bounds.left);
  1059.     bmPtr=(unsigned char*) ((**bmHndl).baseAddr +
  1060. bmBytes*(**bmHndl).bounds.top + 
  1061.             (short)((**bmHndl).bounds.left / 8) );
  1062.  
  1063.     /*Get the number of bytes to increment at the end of a row for each
  1064. image*/
  1065.     bmBit = (**bmHndl).bounds.left % 8;        /*the starting bit for the bitmap*/
  1066.     pmBytes -= cols;
  1067.     bmBytes -= (short)( (cols + bmBit - 1) / 8);
  1068.     
  1069.     bmBit = 7 - bmBit;    /*image bits are reversed from the order they are
  1070. counted*/
  1071.     
  1072.     /*Loop through each row of the images*/
  1073.     for(i=0; i<rows; i++, pmPtr+=pmBytes, bmPtr+=bmBytes) {
  1074.     
  1075.         /*Loop through each column of the images*/
  1076.         for(j=0, k=bmBit; j<cols; j++, pmPtr++, k--) {
  1077.  
  1078.             /*check and set the current bitmap bit, and the bitmap pointer*/
  1079.             if(k == -1) {
  1080.                 bmPtr++;
  1081.                 k = 7;
  1082.             }
  1083.  
  1084.             /*Check that the current PixMap pixel doesn't match the ignored color*/
  1085.             if(*pmPtr != ignoreColor) {
  1086.                 *bmPtr |= (1 << k);
  1087.             } else {
  1088.                 *bmPtr &= (0xff ^ (1 << k));
  1089.             }
  1090.         }
  1091.     }
  1092. }/*MakeMask*/
  1093.  
  1094.  
  1095. /* ######################################################################
  1096. */
  1097.  
  1098.  
  1099. -David Daniel
  1100. daniel@unx.al.alcoa.com
  1101. #######################
  1102. This random sign-off was generated by a statistician.
  1103. #######################
  1104.  
  1105. ---------------------------
  1106.  
  1107. >From Dwayne Knowles <dwayne@bagend.nacjack.gen.nz>
  1108. Subject: Posting an event to another application?
  1109. Date: Tue, 03 May 94 01:23:48 +1200
  1110. Organization: Society for the Prevention of Cruelty to Hobbits
  1111.  
  1112.  
  1113. Is there a way to post an event to another application - eg. a keydown 
  1114. event, without writing my own version of postEvent? I realise this is 
  1115. probably going to break with future system releases and is very uncool in 
  1116. general but I would like to be able to control an application remotely that 
  1117. isn't scriptable or anything. Is this possible?
  1118.  
  1119. Thanks.
  1120.  
  1121. --
  1122.  
  1123. +++++++++++++++++++++++++++
  1124.  
  1125. >From mkb@remarque.berkeley.edu (Mike Brodhead)
  1126. Date: 2 May 1994 17:47:02 GMT
  1127. Organization: STEDT Project, Dept. o' Linguistics, UCBerkeley
  1128.  
  1129. In article <94050301234800677@bagend.nacjack.gen.nz>, Dwayne Knowles
  1130. <dwayne@bagend.nacjack.gen.nz> wrote:
  1131.  
  1132. > Is there a way to post an event to another application - eg. a keydown 
  1133. > event, without writing my own version of postEvent? I realise this is 
  1134. > probably going to break with future system releases and is very uncool in 
  1135. > general but I would like to be able to control an application remotely that 
  1136. > isn't scriptable or anything. Is this possible?
  1137. > Thanks.
  1138. > --
  1139.  
  1140. I doubt you could do this easily from an app, but an INIT can surely
  1141. do it.  Witness QuickKeys.  In fact, you would probably be better off
  1142. installing QK on the machine and sending Apple Events to QK than doing
  1143. everything from scratch.  (I'm asuming this is for in-house use.)
  1144.  
  1145. If you want to code it yourself, you'll have to use the process manager
  1146. to check that the apropriate app is in the foreground before calling
  1147. PostEvent().  You could even force the app to the foreground.
  1148.  
  1149. __________________________________________________________________________
  1150. Mike Brodhead   (New! .sig now 33% shorter!)   <mkb@remarque.berkeley.edu> 
  1151.                     
  1152.  
  1153. +++++++++++++++++++++++++++
  1154.  
  1155. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  1156. Date: Tue, 3 May 1994 14:15:05 +1200 (NZST)
  1157. Organization: (none)
  1158.  
  1159. Dwayne Knowles <dwayne@bagend.nacjack.gen.nz> writes:
  1160. > Is there a way to post an event to another application - eg. a keydown 
  1161. > event, without writing my own version of postEvent? I realise this is 
  1162. > probably going to break with future system releases and is very uncool in 
  1163. > general but I would like to be able to control an application remotely that 
  1164. > isn't scriptable or anything. Is this possible?
  1165.  
  1166. There is only one queue for mouse-downs, keydowns etc, and the frontmost
  1167. application always gets them -- if you want to post events for a particular
  1168. application then move it to the front (using the process manager) and then
  1169. use PostEvent in the normal way...
  1170.  
  1171. +++++++++++++++++++++++++++
  1172.  
  1173. >From Dwayne Knowles <dwayne@bagend.nacjack.gen.nz>
  1174. Date: Thu, 05 May 94 01:46:59 +1200
  1175. Organization: Society for the Prevention of Cruelty to Hobbits
  1176.  
  1177.  
  1178. In article <mkb-020594104417@interzone.hip.berkeley.edu>, Mike Brodhead 
  1179. writes:
  1180.  
  1181. > I doubt you could do this easily from an app, but an INIT can surely
  1182. > do it.  Witness QuickKeys.  In fact, you would probably be better off
  1183. > installing QK on the machine and sending Apple Events to QK than doing
  1184. > everything from scratch.  (I'm asuming this is for in-house use.)
  1185. > If you want to code it yourself, you'll have to use the process manager
  1186. > to check that the apropriate app is in the foreground before calling
  1187. > PostEvent().  You could even force the app to the foreground.
  1188.  
  1189. There are several problems with this however. The receiving app has to be 
  1190. forced into the foreground, and more importantly, postEvent doesn't let me 
  1191. post a keyDown event with the command key as a modifier - eg. post a menu 
  1192. key event.
  1193.  
  1194. Unfortunately I don't have Quickeys.
  1195.  
  1196. --
  1197.  
  1198. +++++++++++++++++++++++++++
  1199.  
  1200. >From jeremyr@dcs.qmw.ac.uk (Jeremy Roussak;Guest of Distributed Systems Lab)
  1201. Date: Wed, 4 May 1994 21:04:28 GMT
  1202. Organization: Computer Science Dept, QMW, University of London
  1203.  
  1204. >> If you want to code it yourself, you'll have to use the process manager
  1205. >> to check that the apropriate app is in the foreground before calling
  1206. >> PostEvent().  You could even force the app to the foreground.
  1207.  
  1208. >There are several problems with this however. The receiving app has to be
  1209. >forced into the foreground, and more importantly, postEvent doesn't let me
  1210. >post a keyDown event with the command key as a modifier - eg. post a menu
  1211. >key event.
  1212.  
  1213. There's no way around forcing the app to the front, since, as
  1214. has been pointed out before, there's only one event queue and
  1215. all the events in it go to the frontmost app.
  1216.  
  1217. However, you can easily post an event with a specific set of
  1218. modifiers: use PPostEvent, which returns a pointer to the queue
  1219. element, and then modify the modifiers field.
  1220.  
  1221. Jeremy
  1222.  
  1223. +++++++++++++++++++++++++++
  1224.  
  1225. >From mkb@remarque.berkeley.edu (Mike Brodhead)
  1226. Date: 5 May 1994 01:56:34 GMT
  1227. Organization: STEDT Project, Dept. o' Linguistics, UCBerkeley
  1228.  
  1229. In article <CpAqJJ.Jpz@dcs.qmw.ac.uk>, jeremyr@dcs.qmw.ac.uk (Jeremy
  1230. Roussak;Guest of Distributed Systems Lab) wrote:
  1231.  
  1232. > However, you can easily post an event with a specific set of
  1233. > modifiers: use PPostEvent, which returns a pointer to the queue
  1234. > element, and then modify the modifiers field.
  1235.  
  1236. This is true.  Still, if QuickKeys will do the job it is probably a
  1237. lot more cost effective to use it.  Divide the cost of QK by the number
  1238. of hours you expect to spend coding.  (Don't forget Hofstadter's law :)
  1239.  
  1240. What is your desired end result?  What will your code accomplish?
  1241. Who will use it?
  1242.  
  1243. __________________________________________________________________________
  1244. Mike Brodhead   (New! .sig now 33% shorter!)   <mkb@remarque.berkeley.edu> 
  1245.                     
  1246.  
  1247. +++++++++++++++++++++++++++
  1248.  
  1249. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  1250. Date: Thu, 5 May 1994 18:36:54 +1200 (NZST)
  1251. Organization: (none)
  1252.  
  1253. Dwayne Knowles <dwayne@bagend.nacjack.gen.nz> writes:
  1254. > > If you want to code it yourself, you'll have to use the process manager
  1255. > > to check that the apropriate app is in the foreground before calling
  1256. > > PostEvent().  You could even force the app to the foreground.
  1257. > There are several problems with this however. The receiving app has to be 
  1258. > forced into the foreground, and more importantly, postEvent doesn't let me 
  1259. > post a keyDown event with the command key as a modifier - eg. post a menu 
  1260. > vkey event.
  1261.  
  1262. No, that's no problem -- you use PPostEvent, which returns a pointer to the
  1263. newly posted event queue element , and you can them diddle the modifiers.
  1264. Just don't call WaitNextEvent first :-)
  1265.  
  1266. -- Bruce
  1267.  
  1268. +++++++++++++++++++++++++++
  1269.  
  1270. >From chris-b@cs.aukuni.ac.nz (Christopher David Burns)
  1271. Date: 5 May 1994 11:22:45 GMT
  1272. Organization: University of Auckland
  1273.  
  1274. Bruce@hoult.actrix.gen.nz (Bruce Hoult) writes:
  1275.  
  1276. >No, that's no problem -- you use PPostEvent, which returns a pointer to the
  1277. >newly posted event queue element , and you can them diddle the modifiers.
  1278. >Just don't call WaitNextEvent first :-)
  1279.  
  1280. Why don't you use the jGNEFilter mechanism instead of PPostEvent(). Simply
  1281. write an app that installs a jGNEFilter. This proc gets called just before
  1282. GetNextEvent() or WaitNextEvent() return. It has access to the boolean
  1283. result and the event record about to be returned. You can simply call
  1284. SetFrontProcess() and in your proc check curAppName (or maybe compare
  1285. GetFrontProcess() with the process you're interested in). When you find
  1286. that the right app is switched in, you can change the first null event to
  1287. a mouseDown (or whatever).
  1288.  
  1289. Simple. (I assume that the jGNEFilter is called on null events).
  1290.  
  1291. Give me a call if you want some code.
  1292.  
  1293. Cheers,
  1294.  
  1295. Chris B
  1296. - ---------------------------------------------------------------------
  1297. NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  1298. Internet:chris-b@cs.aukuni.ac.nz
  1299. Phone: +64 9 373-7599 x5602  Fax: +64 9 373-7453
  1300.  
  1301.  
  1302. +++++++++++++++++++++++++++
  1303.  
  1304. >From zellers@berksys.com (Steve Zellers)
  1305. Date: 5 May 1994 21:17:01 GMT
  1306. Organization: Berkeley Systems, Inc.
  1307.  
  1308. In article <94050501465900688@bagend.nacjack.gen.nz>, Dwayne Knowles
  1309. <dwayne@bagend.nacjack.gen.nz> wrote:
  1310.  
  1311. > postEvent doesn't let me 
  1312. > post a keyDown event with the command key as a modifier - eg. post a menu 
  1313. > key event.
  1314.  
  1315. Check out PPostEvent.
  1316.  
  1317. Consider an INIT/background app combination.
  1318.  
  1319. -- 
  1320. Sr. Software Engineer
  1321. Berkeley Systems, Inc.
  1322.  
  1323. +++++++++++++++++++++++++++
  1324.  
  1325. >From jedavis@CS.Stanford.EDU (James Edward Davis)
  1326. Date: 6 May 1994 14:20:57 -0500
  1327. Organization: UTexas Mail-to-News Gateway
  1328.  
  1329. References: <94050301234800677@bagend.nacjack.gen.nz>
  1330.  
  1331. Dwayne Knowles <dwayne@bagend.nacjack.gen.nz> writes:
  1332.  
  1333. >Is there a way to post an event to another application - eg. a keydown 
  1334. >event, without writing my own version of postEvent? I realise this is 
  1335. >probably going to break with future system releases and is very uncool in 
  1336. >general but I would like to be able to control an application remotely that 
  1337. >isn't scriptable or anything. Is this possible?
  1338.  
  1339. Well, the simple answer is use AutoType. An OSAX I worte that lets 
  1340. AppleScript send keyDowns with modifiers to other apps, so you can script 
  1341. non-scriptable applications. I use ppostevent essentially like others
  1342. in this thread described. Available at fine ftp sites everywhere.
  1343.  
  1344. -James Davis : jedavis@cs.stanford.edu
  1345.  
  1346.  
  1347.  
  1348. +++++++++++++++++++++++++++
  1349.  
  1350. >From walkerj@math.scarolina.edu (Jim Walker)
  1351. Date: 4 May 1994 18:21:50 GMT
  1352. Organization: University of South Carolina - Columbia - Computer Science
  1353.  
  1354. Dwayne Knowles <dwayne@bagend.nacjack.gen.nz> writes:
  1355.  
  1356. (stuff deleted)
  1357. >There are several problems with this however. The receiving app has to be 
  1358. >forced into the foreground, and more importantly, postEvent doesn't let me 
  1359. >post a keyDown event with the command key as a modifier - eg. post a menu 
  1360. >key event.
  1361.  
  1362. PPostEvent (not a typo!) does allow you to post a keyDown event with
  1363. modifiers.
  1364. --
  1365.  
  1366.  -- Jim Walker  USC Dept. of Math.  walkerj@math.scarolina.edu
  1367.  
  1368. ---------------------------
  1369.  
  1370. >From dnebing@bgsu.edu (  Mr. Neb)
  1371. Subject: Shared memory...
  1372. Date: 28 Apr 1994 02:04:11 GMT
  1373. Organization: Bowling Green State University
  1374.  
  1375.   Here's a good one...
  1376.  
  1377.   I have a component which can be opened multiple times.  I don't want
  1378. the components to have to allocate the same memory each time (they
  1379. all share a common resource (a picture) that I don't want multiple
  1380. copies of floating around in memory).  Anyone have a good solution
  1381. for setting up a shared buffer between the components?
  1382.  
  1383. Thanks in advance,
  1384.  
  1385. Dave Nebinger
  1386.  
  1387. ============================================================
  1388. Dave Nebinger                    dnebing@andy.bgsu.edu
  1389. Network Manager, Biology Dept.   dnebing@opie.bgsu.edu
  1390. Bowling Green State University   dnebing@bgsuopie (bitnet)
  1391. Bowling Green, OH 43403          #include <std_disclaimer.h>
  1392.  
  1393.              *THE* alt.sources.mac supporter!
  1394.  
  1395. -- 
  1396. ============================================================
  1397. Dave Nebinger                    dnebing@andy.bgsu.edu
  1398. Network Manager, Biology Dept.   dnebing@opie.bgsu.edu
  1399. Bowling Green State University   dnebing@bgsuopie (bitnet)
  1400.  
  1401. +++++++++++++++++++++++++++
  1402.  
  1403. >From devon_hubbard@taligent.com (Devon Hubbard)
  1404. Date: Thu, 28 Apr 1994 17:35:31 GMT
  1405. Organization: Taligent, Inc.
  1406.  
  1407. In article <2pn5ir$rcm@falcon.bgsu.edu>, dnebing@bgsu.edu (  Mr. Neb)
  1408. wrote:
  1409.  
  1410. >   Here's a good one...
  1411. >   I have a component which can be opened multiple times.  I don't want
  1412. > the components to have to allocate the same memory each time (they
  1413. > all share a common resource (a picture) that I don't want multiple
  1414. > copies of floating around in memory).  Anyone have a good solution
  1415. > for setting up a shared buffer between the components?
  1416. > Thanks in advance,
  1417. > Dave Nebinger
  1418. > ============================================================
  1419. > Dave Nebinger                    dnebing@andy.bgsu.edu
  1420. > Network Manager, Biology Dept.   dnebing@opie.bgsu.edu
  1421. > Bowling Green State University   dnebing@bgsuopie (bitnet)
  1422. > Bowling Green, OH 43403          #include <std_disclaimer.h>
  1423. >              *THE* alt.sources.mac supporter!
  1424.  
  1425. Install your own _Gestalt selector.  Whichever process is first, it
  1426. installs the selector.  The other checks for it's existance.  If there, the
  1427. selector returns the address of a struct that contains whatever you want
  1428. (i.e. addresses of shared memory blocks).  Any of your processes can get to
  1429. it.  If you're starting and quitting apps, allocate the memory in the
  1430. system heap so it'll stick around.  Just be friendly and clean up the
  1431. memory when everything's done.
  1432.  
  1433. dEVoN
  1434.  
  1435. - ------------------------------------------------------------------------
  1436. Devon Hubbard                                                Silicon Pilot
  1437. devon_hubbard@taligent.com                                   Taligent, Inc
  1438.  
  1439. +++++++++++++++++++++++++++
  1440.  
  1441. >From sblack@us.oracle.com (Steven T. Black)
  1442. Date: 28 Apr 94 22:15:44 GMT
  1443. Organization: Oracle Corporation
  1444.  
  1445. In article <devon_hubbard-280494093531@saucer.taligent.com>
  1446. devon_hubbard@taligent.com (Devon Hubbard) writes:
  1447.  
  1448. > In article <2pn5ir$rcm@falcon.bgsu.edu>, dnebing@bgsu.edu (  Mr. Neb)
  1449. > wrote:
  1450. > >   Here's a good one...
  1451. > > 
  1452. > >   I have a component which can be opened multiple times.  I don't want
  1453. > > the components to have to allocate the same memory each time (they
  1454. > > all share a common resource (a picture) that I don't want multiple
  1455. > > copies of floating around in memory).  Anyone have a good solution
  1456. > > for setting up a shared buffer between the components?
  1457. > > 
  1458. > > Thanks in advance,
  1459. > > 
  1460. > > Dave Nebinger
  1461. > > 
  1462. > > ============================================================
  1463. > > Dave Nebinger                    dnebing@andy.bgsu.edu
  1464. > > Network Manager, Biology Dept.   dnebing@opie.bgsu.edu
  1465. > > Bowling Green State University   dnebing@bgsuopie (bitnet)
  1466. > > Bowling Green, OH 43403          #include <std_disclaimer.h>
  1467. > > 
  1468. > >              *THE* alt.sources.mac supporter!
  1469. > > 
  1470. > Install your own _Gestalt selector.  Whichever process is first, it
  1471. > installs the selector.  The other checks for it's existance.  If there, the
  1472. > selector returns the address of a struct that contains whatever you want
  1473. > (i.e. addresses of shared memory blocks).  Any of your processes can get to
  1474. > it.  If you're starting and quitting apps, allocate the memory in the
  1475. > system heap so it'll stick around.  Just be friendly and clean up the
  1476. > memory when everything's done.
  1477. > dEVoN
  1478. > --------------------------------------------------------------------------
  1479. > Devon Hubbard                                                Silicon Pilot
  1480. > devon_hubbard@taligent.com                                   Taligent, Inc
  1481.  
  1482. You can also use the ASLM (Shared Library Manager) to store the
  1483. resource in a library, and have a routine that returns the address of
  1484. the PICT.  This has the advantage that the ASLM can monitor how many
  1485. clients are using the PICT, and so won't flush it from memory when the
  1486. original app that called it quits if other apps are still referencing
  1487. it.  It also takes care of flushing it from memory when it is no longer
  1488. needed.
  1489.  
  1490. - ----------------------------------------------------------------------
  1491. --
  1492. Steven T. Black                                     Lead Technical
  1493. Staff
  1494. sblack@us.oracle.com                                Oracle Desktop
  1495. Products
  1496.  
  1497. +++++++++++++++++++++++++++
  1498.  
  1499. >From dnebing@falcon.bgsu.edu.bgsu.edu (  Mr. Neb,217 LSC,3722332,3531532)
  1500. Date: 29 Apr 1994 15:42:56 GMT
  1501. Organization: Bowling Green State University
  1502.  
  1503. sblack@us.oracle.com (Steven T. Black) writes:
  1504. > You can also use the ASLM (Shared Library Manager) to store the
  1505. > resource in a library, and have a routine that returns the address of
  1506. > the PICT.  This has the advantage that the ASLM can monitor how many
  1507. > clients are using the PICT, and so won't flush it from memory when the
  1508. > original app that called it quits if other apps are still referencing
  1509. > it.  It also takes care of flushing it from memory when it is no longer
  1510. > needed.
  1511.  
  1512.   This assumes the following:
  1513.  
  1514.     1.  That somehow you have the ASLM headers and libs necessary to
  1515. do so.
  1516.  
  1517.     2.  That the user has the ASLM or that Apple will give you a
  1518. license to distribute it in your shareware/freeware.
  1519.  
  1520.  
  1521.   I would love to use the ASLM because it would simplify my life
  1522. a great deal.  Currently I am implementing my package as a bunch
  1523. of components because Apple chooses to make me pay for the headers
  1524. and libraries needed to use the ASLM.
  1525.  
  1526.   The way I figure it, if Apple wanted me to use new functionality
  1527. within the system then they would provide the headerws and libs
  1528. necessary to do so.
  1529.  
  1530.   I can't even get the Universal Headers without purchasing a
  1531. major upgrade.
  1532.  
  1533.   Without the necessary headers, my stuff won't use the
  1534. DragMgr, PowerTalk, etc.  So people who use my stuff won't see
  1535. any reason to go buy the components from Apple.  So you tell
  1536. me who is really hurt by charging for these simple development
  1537. products.  Like I was quoted in the latest MacWEEK, I don't
  1538. expect to get the components for free.  But I don't think that
  1539. the headers and libs needed to implement the functionality of
  1540. those components is too much to ask for.
  1541.  
  1542. ============================================================
  1543. Dave Nebinger                    dnebing@andy.bgsu.edu
  1544. Network Manager, Biology Dept.   dnebing@opie.bgsu.edu
  1545. Bowling Green State University   dnebing@bgsuopie (bitnet)
  1546. Bowling Green, OH 43403          #include <std_disclaimer.h>
  1547.  
  1548.              *THE* alt.sources.mac supporter!
  1549. -- 
  1550. ============================================================
  1551. Dave Nebinger                    dnebing@andy.bgsu.edu
  1552. Network Manager, Biology Dept.   dnebing@opie.bgsu.edu
  1553. Bowling Green State University   dnebing@bgsuopie (bitnet)
  1554.  
  1555. +++++++++++++++++++++++++++
  1556.  
  1557. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  1558. Date: 30 Apr 94 15:01:20 +1200
  1559. Organization: University of Waikato, Hamilton, New Zealand
  1560.  
  1561. In article <2pn5ir$rcm@falcon.bgsu.edu>, dnebing@bgsu.edu (  Mr. Neb) writes:
  1562. >
  1563. >   I have a component which can be opened multiple times.  I don't want
  1564. > the components to have to allocate the same memory each time (they
  1565. > all share a common resource (a picture) that I don't want multiple
  1566. > copies of floating around in memory).  Anyone have a good solution
  1567. > for setting up a shared buffer between the components?
  1568.  
  1569. You could use SetComponentRefcon and GetComponentRefcon. The Component Manager
  1570. documentation makes it clear that a component only has a single Refcon value,
  1571. no matter how many instances are open.
  1572.  
  1573. If you want to dispose of the storage when the last instance is closed,
  1574. you can just call CountComponentInstances on yourself in your CloseComponent
  1575. handler. I assume the count isn't decremented until your CloseComponent
  1576. handler returns, in which case the value to check for is 1. If the count
  1577. _is_ decremented before entering your CloseComponent handler, then the value
  1578. to check for is 0.
  1579.  
  1580. Or you could avoid the question and maintain your own reference count...
  1581.  
  1582. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  1583. Info & Tech Services Division              fax: +64-7-838-4066
  1584. University of Waikato            electric mail: ldo@waikato.ac.nz
  1585. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
  1586.  
  1587. +++++++++++++++++++++++++++
  1588.  
  1589. >From jim_reekes@quickmail.apple.com (Jim Reekes)
  1590. Date: Tue, 3 May 1994 19:56:15 GMT
  1591. Organization: Apple Computer, Inc.
  1592.  
  1593. In article <1994Apr30.150120.28180@waikato.ac.nz>, ldo@waikato.ac.nz
  1594. (Lawrence D'Oliveiro, Waikato University) wrote:
  1595. > In article <2pn5ir$rcm@falcon.bgsu.edu>, dnebing@bgsu.edu (  Mr. Neb) writes:
  1596. > >
  1597. > >   I have a component which can be opened multiple times.  I don't want
  1598. > > the components to have to allocate the same memory each time (they
  1599. > > all share a common resource (a picture) that I don't want multiple
  1600. > > copies of floating around in memory).  Anyone have a good solution
  1601. > > for setting up a shared buffer between the components?
  1602. > You could use SetComponentRefcon and GetComponentRefcon. The Component Manager
  1603. > documentation makes it clear that a component only has a single Refcon value,
  1604. > no matter how many instances are open.
  1605. > If you want to dispose of the storage when the last instance is closed,
  1606. > you can just call CountComponentInstances on yourself in your CloseComponent
  1607. > handler. I assume the count isn't decremented until your CloseComponent
  1608. > handler returns, in which case the value to check for is 1. If the count
  1609. > _is_ decremented before entering your CloseComponent handler, then the value
  1610. > to check for is 0.
  1611. > Or you could avoid the question and maintain your own reference count...
  1612. > Lawrence D'Oliveiro                       fone: +64-7-856-2889
  1613. > Info & Tech Services Division              fax: +64-7-838-4066
  1614. > University of Waikato            electric mail: ldo@waikato.ac.nz
  1615. > Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
  1616.  
  1617. Lawrence is right. For components, the refCon was designed exactly for this
  1618. purpose. Only one thing to consider, if the system heap is tight and cannot
  1619. load your component there, then it will be "cloned" into the current
  1620. application heap (the heap that is responsible for opening it). When a
  1621. component is cloned it will not carry it's refCon from the parent. In this
  1622. case you need to check by calling GetComponentInstanceA5. A nil value means
  1623. you're in the system heap, but any value will mean you're in some
  1624. application's context.
  1625.  
  1626. - ---------------------------------------------------------------------
  1627. Jim Reekes, Polterzeitgeist   |     Macintosh Toolbox Engineering
  1628.                               |          Sound Manager Expert
  1629. Apple Computer, Inc.          | "All opinions expressed are mine, and do
  1630. 20525 Mariani Ave. MS 302-3KS |   not necessarily represent those of my
  1631. Cupertino, CA 95014           |       employer, Apple Computer Inc."
  1632.  
  1633. ---------------------------
  1634.  
  1635. >From Anders.Wahlin@hum.gu.se (Anders Wahlin)
  1636. Subject: Unmounting all volumes?
  1637. Date: Tue, 3 May 1994 08:03:46 GMT
  1638. Organization: Hum Fak:s Dataservice
  1639.  
  1640. I would like to know how I can unmount all volumes (except for the system
  1641. volume). I would like to do this without knowing the names or the reference
  1642. number of them. Should I do this in loop and not care about the errorcodes?
  1643.  
  1644. Thanks!
  1645.  
  1646. -- 
  1647. Anders Wahlin
  1648. Anders.Wahlin@hum.gu.se
  1649.  
  1650. +++++++++++++++++++++++++++
  1651.  
  1652. >From jumplong@aol.com (Jump Long)
  1653. Date: 3 May 1994 16:03:02 -0400
  1654. Organization: America Online, Inc. (1-800-827-6364)
  1655.  
  1656. In article <Anders.Wahlin-030594100014@bigmac.hds.gu.se>,
  1657. Anders.Wahlin@hum.gu.se (Anders Wahlin) writes:
  1658.  
  1659. > I would like to know how I can unmount all volumes (except for the system
  1660. > volume). I would like to do this without knowing the names or the reference
  1661. > number of them. Should I do this in loop and not care about the errorcodes?
  1662.  
  1663. You can get a list of mounted volumes by calling PBHGetVInfo starting with
  1664. ioVolIndex==1 and then incrementing ioVolIndex until you get an error.  Each
  1665. call to PBHGetVInfo will give you a mounted volume's volume reference number in
  1666. ioVRefNum.  With that volume reference number, you'll be able to unmount
  1667. volumes that don't have any non-system files open on them with PBUnmountVol. 
  1668. If any non-system files are open on a volume, PBUnmountVol will return fBsyErr
  1669. (-47) and the volume won't be unmounted.  There's function named
  1670. UnmountAndEject in the DTS sample code MoreFiles that you can use to unmount
  1671. and eject (if needed) a volume correctly.
  1672.  
  1673. IMPORTANT WARNING: Some programmers have found and used the _UnmountVol trap
  1674. with the HFS bit set (PBHUnmountVol which isn't in Files.h) to unconditionally
  1675. unmount volumes that have open files.  DON'T EVER DO THAT!  PBHUnmountVol is
  1676. reserved for system use at shutdown when volumes need to be unmounted no matter
  1677. what because the system is either going to be shut off or restarted.  Use of
  1678. PBHUnmountVol at any other time can, and usually does, cause serious file and
  1679. volume corruption because all open files on the volume unmounted by
  1680. PBHUnmountVol are slammed closed by the file system that owns the volume. If
  1681. one of those "slammed closed" file's File Control Blocks (FCB) is reused to
  1682. open another file and the program that opened the first file writes to it or
  1683. closes it, it will be accessing the wrong file!  For a good explanation of how
  1684. closing files more than once (which is another thing that can happen if
  1685. PBHUnmountVol is used) can really screw things up, see the Technical Note "HFS
  1686. Elucidations" (used to be TN #102).
  1687.  
  1688. -- Jim Luther
  1689.  
  1690.  
  1691. ---------------------------
  1692.  
  1693. End of C.S.M.P. Digest
  1694. **********************
  1695.  
  1696.  
  1697.  
  1698.